package com.dragon.www.smarthome.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.dragon.www.smarthome.R;
import com.dragon.www.smarthome.entity.User;

/**
 * Created by liqp on 2016/6/7.
 */
public class LoginDialog extends Dialog {

    private TextView tv_username;
    private Button bt_loginout;
    private Button bt_changepassword;
    private OnSelectListener listener;
    private User user;


    public LoginDialog(Context context) {
        super(context);
    }

    @Override
    protected final void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_login);
        tv_username = (TextView) findViewById(R.id.tv_username);
        bt_loginout = (Button) findViewById(R.id.bt_loginout);
        bt_changepassword = (Button) findViewById(R.id.bt_changepassword);

        tv_username.setText(user.getUserName());

        bt_loginout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.loginout();
                }
            }
        });

        bt_changepassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.changepassword();
                }
            }
        });



    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    public void setUser(User user){
        this.user = user;
    }

    public void setLisntener(OnSelectListener listener) {
        this.listener = listener;
    }

    public static abstract interface OnSelectListener {
        public abstract void loginout();
        public abstract void changepassword();
    }

}
